package com.banana.manager.forest.controller.handle;

import com.banana.manager.forest.entity.handle.AreaBean;
import com.banana.manager.forest.entity.handle.ClassBean;
import com.banana.manager.forest.service.impl.handle.ClassServiceImpl;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/class")
public class ClassController {

    @Resource
    private ClassServiceImpl classService;

    @PostMapping("/addClass")
    public ClassBean addClass(@RequestBody ClassBean classBean, @Param("areaId") Integer areaId){
        return classService.addClass(classBean,areaId);
    }

    /**
     * 这里查询一个小班其实查询的是区域，需要传入区域的id
     * @param areaId
     * @return
     */
    @GetMapping("/showClass")
    public AreaBean showClass(Integer areaId){
        return classService.findOneById(areaId);
    }

    @PostMapping("/updateClass")
    public ClassBean updateClass(@RequestBody ClassBean classBean){
        return classService.updateClass(classBean);
    }

    @GetMapping("/displayClass")
    public PageInfo<AreaBean> getClassPages(Integer page, String className, String areaName){
        return classService.findBlurByPage(page, className, areaName);
    }

    @GetMapping("/getAllClass")
    public List<ClassBean> getAllClass(){
        return classService.showAllClass();
    }

}
